package com.jixiantubu.luntan;

import com.example.jixiantubu.R;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class TopFragment extends Fragment {
	TextView t1, t2, t3;
	ICallBack iCallBack;
	ImageView imageView;

	public interface ICallBack {
		// title表示传给中间碎片的文本，alg标志是哪个模块传的
		public void danamicLoad(String title, int flag);
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		iCallBack = (ICallBack) activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.topbar, null);		
		t1 = (TextView) view.findViewById(R.id.quanbu);
		t2 = (TextView) view.findViewById(R.id.jingpin);
		t3 = (TextView) view.findViewById(R.id.tupian);
		imageView=(ImageView)view.findViewById(R.id.write);
		setlistener();
		return view;
	}
	private void setlistener() {
		// 监听TextView单击事件
		t1.setOnClickListener(onClickListener);
		t2.setOnClickListener(onClickListener);
		t3.setOnClickListener(onClickListener);
		imageView.setOnClickListener(onClickListener);
	}

	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			switch (arg0.getId()) {
			case R.id.quanbu:
				iCallBack.danamicLoad("全部", 1);
				break;
			case R.id.jingpin:
				iCallBack.danamicLoad("精品", 5);
				break;
			case R.id.tupian:
				iCallBack.danamicLoad("图片", 6);
				break;
			case R.id.write:
				Intent intent =new Intent(getActivity(),FatieActivity.class);
				startActivity(intent);
				break;
			default:
				break;
			}

		}
	};
}
